<template>
  <el-card>
    <div slot="header" class="clearfix">
      <span>订单回收站</span>
    </div>
    <div class="home-container">

      <!--<v-searchForm :form-data="filter_info" :form-title="formTitle"/>-->

      <!--<v-tableBtns-->
        <!--:show-export="false"-->
        <!--:show-del="true"-->
        <!--@del="delMultiple"-->
      <!--/>-->
      <v-table
        :table-title="tableTitle"
        :table-data="tableData"
        :editable="false"
        :recoverable="true"
        :default-operate="false"
        @sortChange="sortChange"
        @recover="recover"
        @del="del"
      />

      <v-pagination
        :page-info="pageInfo"
        :get-table-list="getTableList"
      />
    </div>
  </el-card>
</template>

<script>
import { mapGetters } from 'vuex'
import UploadExcelComponent from '@/components/UploadExcel/index.vue'

export default {
  name: 'Home',
  components: { UploadExcelComponent },
  data() {
    return {
      // f分页
      pageInfo: {
        pageNumber: 1,
        pageSize: 30,
        totalPage: 0,
        totalRow: 0
      },

      // 排序
      sidx: 'a.deleted_at',
      sortKey: null,

      formTitle: [
        {
          cn: '订单id：',
          en: 'ad_id'
        },
        {
          cn: '广告主：',
          en: 'ad_name'
        },
        {
          cn: '公众号：',
          en: 'name'
        },
        {
          cn: '商务：',
          en: 'swname',
          placeholder: '输入全称'
        },
        {
          cn: '收款状态：',
          en: 'is_receive',
          type: 'select',
          list: [
            {
              label: '未收款',
              value: 0
            },
            {
              label: '已收款',
              value: 2
            }
          ]
        },
        {
          cn: '合同编号：',
          en: 'contract_num',
          type: 'select',
          list: [
            {
              label: '有',
              value: 1
            },
            {
              label: '无',
              value: 0
            }
          ]
        },
        {
          cn: '是否开票：',
          en: 'is_bill',
          type: 'select',
          list: [
            {
              label: '是',
              value: 1
            },
            {
              label: '否',
              value: 0
            }
          ]
        },
        {
          cn: '发布时间：',
          en: 'created_at',
          type: 'time'
        }
      ],
      filter_info: {},

      tableTitle: [
        {
          cn: 'id',
          en: 'ad_id',
          width: '80px',
          sortable: true
        },
        {
          cn: '公众号',
          en: 'name',
          sortable: true
        },
        {
          cn: '版位',
          en: 'ad_place_name'
        },
        {
          cn: '发布时间',
          en: 'publish_at',
          sortable: true
        },
        {
          cn: '广告主',
          en: 'ad_name'
        },
        {
          cn: '金额',
          en: 'ad_price',
          sortable: true
        },
        {
          cn: '商务',
          en: 'swname',
          sortable: true
        },
        {
          cn: '删除人',
          en: 'delete_user'
        },
        {
          cn: '删除时间',
          en: 'a.deleted_at',
          formatter:(a,b)=>{
            return a['a.deleted_at']
          },
          width: '180px',
          sortable: true
        },
        // {
        //   cn: '开票状态',
        //   en: 'invoice_state'
        // }
      ],
      tableData: [],

    }
  },
  activated(){
    this.getTableList()
  },
  computed: {
    ...mapGetters([
      'name',
      'roles'
    ]),
    filter_infos() {
      const data = {}
      const origin = this.filter_info
      for (const key in origin) {
        if (!this.filter_info[key] && this.filter_info[key] !== 0) {
          this.$delete(this.filter_info, key)
          continue
        }
        if (key === 'created_at') {
          data.start_time = origin[key][0]
          data.End_time = origin[key][1]
        } else {
          data[key] = origin[key]
        }
      }
      if (!origin.created_at) {
        delete data.start_time
        delete data.End_time
      }
      return data
    }
  },
  methods: {
    getTableList() {
      const loading = this.$loading()
      const datas = {
        ...this.filter_infos,
        page: this.pageInfo.pageNumber, rows: this.pageInfo.pageSize,
        sidx: this.sidx,
        sortKey: this.sortKey,
        type: 4
      }
      this.$get('action/WechatAdvs/dataGrid', datas)
        .then(res => {
          let list
          const data = res.data
          if (data.list && data.list.length) {
            list = data.list.map((item, index) => {
              // item['a.deleted_at'] = 2134
              return item
            })
          }
          this.pageInfo.totalPage = data.totalPage
          this.pageInfo.totalRow = data.totalRow
          this.tableData = list || []
          loading.close()
        })
        .catch(err => {
          loading.close()
          this.$message({
            message: '获取数据失败',
            type: 'error'
          })
        })
    },
    // 搜索
    search() {
      this.pageInfo.pageNumber=1
      this.getTableList()
    },
    reset() {
      this.filter_info = {}
      this.getTableList()
    },
    delMultiple() {

    },
    // 排序
    sortChange({column, prop, order}) {
      this.sidx = prop || 'a.deleted_at'
      this.sortKey = order === 'ascending' ? 'asc' : null
      this.getTableList()
    },

    recover(val) {
      console.log(val)
    },
    del(val) {
      console.log(val)
    }

  }
}
</script>
